package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone    string `gorm:"type:char(11);not null;comment:'手机号'"`
	Password string `gorm:"type:varchar(32);not null;comment:'密码'"`
	Image    string `gorm:"type:varchar(500);not null;comment:'头像'"`
	NickName string `gorm:"type:varchar(300);not null;comment:'昵称'"`
}

func (u *User) FindUserByPhone(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone=?", phone).First(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UserUpdate(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone=?", phone).Updates(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}
